Objetivo: Realizar un heatmap con datos geneticos

En este ejercicio vamos a: 1. Cargar nuestra matriz hipotética de datos y dataframes adicionales 2. Realizar varios heatmaps

Para este laboratorio debemos instalar el programa de heatmap y llamarlo

install.packages("pheatmap")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0'
## (as 'lib' is unspecified)
library(pheatmap)

Vamos a trabajar con tres archivos, utilzamos file.choose() para localizarlos (si lo integro, me marca error en MD) y los nombramos así, Al archivo de heatmap_data.csv lo nombramos genes

genes <- as.matrix(
  read.csv("/cloud/project/heatmap_data.csv",
           sep = "," ,
           header = T,
           row.names = 1))

Al archivo de annotation_col.csv lo nombramos annotation_col

annotation_col <- read.csv("/cloud/project/annotation_col.csv",
           header = T,
           row.names = 1)

Al archivo de annotation_rol.csv lo nombramos annotation_row

annotation_row <- read.csv("/cloud/project/annotation_row.csv",
                           header = T,
                           row.names = 1)

Ahora vamos a graficar con pheatmap a genes

pheatmap(genes)

Para cambiar el tamaño de letra en el gráfico heatmap

pheatmap(genes, fontsize = 6)

Se puede observar que por default se tienen los clùsters de las filas y columnas cluster by gene - groups of similar genes—-LOS GENES ESTAN EN LOS RENGLONES (clusteo por default pero lo podemos quitar tanto en pacientes como genes) POR DEFAULT CLUSTEA LOS RENGLONES

pheatmap(genes, fontsize = 6, cluster_rows = T, cluster_cols = F)

Para clustear por pacientes DEBES HACER QUE LAS COLUMNAS SE TRANFOMEN A RENGLONES

pheatmap(genes, fontsize = 6, cluster_rows = F, cluster_cols = T)

Como usualmente lo grafica

pheatmap(genes, fontsize = 6, cluster_rows = T, cluster_cols = T)

Vamos añadir anotaciones a nuestro gráfico para entender mejor la información, agregamos anotaciones a las filas (genes)

pheatmap(genes, fontsize = 6, cluster_rows = T, cluster_cols = T, annotation_row = annotation_row)

Agregamos anotaciones a las columnas (pacientes), con esto se tiene la información de la condición y tipo de droga

pheatmap(genes, fontsize = 6, cluster_rows = T, cluster_cols = T, annotation_row = annotation_row, annotation_col = annotation_col)

Realizar Gráfica completa a la que quitamos dendogramas

pheatmap(genes, fontsize = 6, cluster_rows = T, cluster_cols = T, annotation_row = annotation_row, annotation_col = annotation_col, treeheight_row = 0, treeheight_col = 0, main = "Expresión Genética")

Tomar datos de la matriz, creas submatrices

sub <- genes [c(1:5, 55:60), c(1:5, 20:35, 55:60)]

Graficar submatriz del paso anterior

pheatmap(sub, fontsize = 6, cluster_rows = T, cluster_cols = T, annotation_row = annotation_row, annotation_col = annotation_col, treeheight_row = 0, treeheight_col = 0, main = "Expresión Genética")

Con subset 2 – DESPLEGAR VALORES

pheatmap(sub, fontsize = 8, cluster_rows = T, cluster_cols = T, annotation_row = annotation_row, annotation_col = annotation_col, treeheight_row = 0, treeheight_col = 0, main = "Expresión Genética", annotation_legend = FALSE, display_numbers = TRUE, fontsize_number = 6)

Para tener nueva paleta de colores en tus heatmaps, debes instalar viridis

install.packages("viridis")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0'
## (as 'lib' is unspecified)
library(viridis)
## Loading required package: viridisLite

Los colores magma, plasma, viridis, inferno

pheatmap(sub, fontsize = 8, cluster_rows = T, cluster_cols = T, annotation_row = annotation_row, annotation_col = annotation_col, treeheight_row = 0, treeheight_col = 0, main = "Expresión Genética", annotation_legend = FALSE, display_numbers = TRUE, fontsize_number = 6, color = viridis_pal(option = "magma") (6))

ELEMENTOS ADICIONALES EN TUS HEATMAPS Distancias entre los elementos (MATRIZ)

dist(sub)
##           Gene1    Gene2    Gene3    Gene4    Gene5   Gene55   Gene56   Gene57
## Gene2  6.506125                                                               
## Gene3  7.823569 7.021725                                                      
## Gene4  5.253565 7.649124 6.516104                                             
## Gene5  6.411847 5.977640 5.967513 6.184570                                    
## Gene55 5.703940 6.969997 7.096321 6.837653 7.534618                           
## Gene56 4.544832 6.723925 6.542745 5.805165 5.150859 6.028094                  
## Gene57 6.124657 6.069362 5.550487 6.004035 3.881691 7.122986 5.209746         
## Gene58 7.417422 8.796956 8.462521 7.874145 8.030439 6.777444 6.292359 7.669524
## Gene59 6.189649 8.293720 7.977707 6.115718 5.821355 7.317126 4.835770 6.104449
## Gene60 6.623226 8.133474 7.665999 6.837342 7.659167 7.569942 6.373711 7.296198
##          Gene58   Gene59
## Gene2                   
## Gene3                   
## Gene4                   
## Gene5                   
## Gene55                  
## Gene56                  
## Gene57                  
## Gene58                  
## Gene59 8.312043         
## Gene60 7.813793 6.992657

Correlación pacientes

pheatmap(cor(sub))

Correlación genes (Primero se calcula la matriz transpuesta de sub y luego la correlación)

trans <- t(sub)
pheatmap(cor(trans))

FIN DE LA PRÁCTICA